package org.esti.model.utils;

import org.esti.service.KnowledgeFieldService;
import org.springframework.beans.factory.annotation.Autowired;

import java.beans.PropertyEditorSupport;

/**
 * @author Artem Loginov (logart)
 */
public class KnowledgeFieldPropertyEditor extends PropertyEditorSupport {
    @Autowired
    private final KnowledgeFieldService knowledgeFieldService;


    public KnowledgeFieldPropertyEditor(KnowledgeFieldService knowledgeFieldService) {
        this.knowledgeFieldService = knowledgeFieldService;
    }


    @Override
    public void setAsText(String levelId) {
        Long id = Long.parseLong(levelId);
        super.setValue(knowledgeFieldService.getKnowledgeFieldById(id));
    }
}
